package com.dongzhu1428.express.module1.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dongzhu1428.express.module1.Result;
import com.dongzhu1428.express.module1.dto.controllerDto.ResignToBeDeliverymanParams;
import com.dongzhu1428.express.module1.dto.controllerDto.User.GetDeliverymanInfo;
import com.dongzhu1428.express.module1.entity.Deliveryman;
import com.dongzhu1428.express.module1.mapper.express.DeliverymanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
  @Autowired
    DeliverymanMapper deliverymanMapper;

 public  Result<Boolean> isDeliveryman(int userId){

      Deliveryman deliveryman = deliverymanMapper.selectOne(new QueryWrapper<Deliveryman>().eq("user_id", userId));
      if(deliveryman !=null){
          return  Result.success(true);
      }
      else return Result.success(false);

  }

    public  Result<String> registerToBeDeliveryman(ResignToBeDeliverymanParams dto){

     deliverymanMapper.insert(Deliveryman.builder()
                     .userId(dto.getUserId())
                     .dPhone(dto.getDPhone())
             .build());

     return Result.success(null,"注册成功");

    }


    public  Result<GetDeliverymanInfo> getDeliverymanInfo(int id){
        GetDeliverymanInfo deliverymanInfo = deliverymanMapper.getDeliverymanInfo(id);
       return Result.success(deliverymanInfo);
    }
}
